/* 
	@Copyright (c) 2007 by Denis Riabtchik. All rights reserved. See license.txt and http://jgrouse.com for details@
	$Id: RefContainer.java 571 2009-02-28 19:11:49Z denis.riabtchik $
*/

package jgrouse.jgdoc.elements;

import java.io.Serializable;

import jgrouse.jgdoc.Vocabulary;
import jgrouse.jgdoc.api.IComment;
import jgrouse.jgdoc.api.IDocElement;
import jgrouse.jgdoc.api.IDocElementList;


public abstract class RefContainer extends BaseRefContainer implements  Serializable
{

	private static final long serialVersionUID = -6297958188822496200L;

	public RefContainer()
	{
		super();
	}
	
	public RefContainer(IComment pComment)
	{
		super(pComment);
	}
	
	public void addChild(IDocElement pElement)
	{
		RefElement re = new RefElement(pElement);
		m_children.put(re.getName(),re);
		pElement.setPhysOwner(this);
	}

	
	public IDocElementList get(String tagName)
	{
		IDocElementList result = new DocElementList();
		for (RefElement re : m_children.values())
		{
			IDocElement de = re.getRef();
			if (de.getCommentType().equals(tagName))
			{
				if (de.getOwner() == null || de.getOwner().getComment() == null || 
						de.getOwner().getComment().getCommentType() == Vocabulary.NAMESPACE)
				{
					result.add(re.getRef());
				}
			}
		}
		return result;
	}
	
	@Override
	protected String getText()
	{
		StringBuffer sb = new StringBuffer("<children>");
		for (RefElement entry : m_children.values())
		{
			IDocElement de = entry.getRef();
			if (de.getOwner() == null || de.getOwner().getComment() == null || 
					de.getOwner().getComment().getCommentType() == Vocabulary.NAMESPACE)
			{
				sb.append(entry.toString()).append('\n');
			}
		}
		sb.append("</children>");
		return sb.toString();
	}
	
	public boolean isLogicalContainer()
	{
		return false;
	}

}
